<%@ page language="java" import="java.util.*,java.sql.*,javass.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>页面</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="./my1.css" rel="stylesheet" type="text/css">
   <script src="./jquery-2.1.0.js"></script>   
  </head>
  
  <body>
   <script type="text/javascript">
 	$(function(){
 		$.ajax({
            type: "GET",//1.type:get/post
            url: "./Fenyeservlet?current=0",
            dataType: "json",
            contentType:"application/json",
            success: function(data){

                console.log("success");
                $("#t1").html(data[0].title);
                $("#t2").html(data[0].auto);
                $("#t3").html(data[0].date);
                $("#tt1").html(data[1].title);
                $("#tt2").html(data[1].auto);
                $("#tt3").html(data[1].date);
            },
            error: function(data){
                console.log("error");
                  console.log(data);
                 
            }
        });
 		$(".chose").click(function(){
 			
 			$.ajax({
 	            type: "GET",//1.type:get/post
 	            url: "./Fenyeservlet?current="+(this.innerHTML-1),
 	            dataType: "json",
 	            contentType:"application/json",
 	            success: function(data){

 	                console.log("success");
 	               console.log(this.innerHTML);
 	               if(data.length==2){
 	            	$("#tt1").show();
 		            $("#tt2").show();
 		            $("#tt3").show();
 	                $("#t1").html(data[0].title);
 	                $("#t2").html(data[0].auto);
 	                $("#t3").html(data[0].date);
 	                $("#tt1").html(data[1].title);
 	                $("#tt2").html(data[1].auto);
 	                $("#tt3").html(data[1].date);
 	            }else{
 	            	$("#t1").html(data[0].title);
 	                $("#t2").html(data[0].auto);
 	                $("#t3").html(data[0].date);
 	               	$("#tt1").hide();
	                $("#tt2").hide();
	                $("#tt3").hide();
 	            }
 	            },
 	            error: function(data){
 	                console.log("error");
 	                  console.log(data);
 	                 
 	            }
 		});
 		
 	});
 	});
 </script>
    <div id="out">
    <div id="title" class="in">
        <p id="title_text">欢迎登录软通培训论坛</p>
        <div>
           
            <div id="login">用户：<%=LoginServlet.n1 %>|
            <a href="./fatie.jsp">发帖|</a>
            <a href="./reset.jsp">重置密码|</a>
            <a href="./MyJsp.jsp">注销</a>
            
            </div>

        </div>
    </div>
    <div id="left" class="in">
        <form id="form1" name="form" action="#">
            <input class="left_input" type="submit" value="学生讨论"><br>
        </form>
    </div>
    <div id="right" class="in">
        <table id="table1"  border="1">
            <tr>
                <th>帖子标题</th><th>发帖人</th><th>最后修改时间</th>
            </tr>
            
       
            <tr>
                <th id="t1"></th><td id="t2"></td><td id="t3"></td>
            </tr>
            <tr>
                <th id="tt1"></th><td id="tt2"></td><td id="tt3"></td>
            </tr>

        </table>
        <div style="float: right;">
        <table >
        <tr><td class="chose">首页</td>
        <%
        ConnectionUtil connutil=new ConnectionUtil();
		Connection conn = connutil.getConn();
		PreparedStatementUtil psu=new PreparedStatementUtil();
		ResultSetUtil rsu=new ResultSetUtil(); 
		String sql0=" SELECT COUNT(v1.title)FROM v1; ";
		PreparedStatement ps0=psu.getPreparedStatement(conn, sql0);
		ResultSet rs0=rsu.getResultSet(ps0);
		int count=0;
		if(rs0.next()){
			count= rs0.getInt(1);
		}
		
		final int pagesize=2;//每页显示条数
		int pagecount=0;//总页数
		 if(count%pagesize==0){//如果能整除
			 	  pagecount=count/pagesize;
		      }else{
		    	  pagecount=(int)(count/pagesize)+1;
		      }
        %>
		<%for(int i=1;i<=pagecount;i++){ %>
	    <td class="chose" style="border: 2px;"><%=i %></td>
	    <%} %>

		<td class="chose">尾页</td>
		</tr>
		</table>
        </div>
    
    </div>
</div>


  </body>
</html>
